<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Day 5. EasyX显示图像的基本步骤 全部代码在main.cpp中完成  0. 安装EasyX库从EasyX下载EasyX安装程序，安装即可。 1. 增加头文件1include &lt;graphics.h&gt;	&#x2F;&#x2F;使用EasyX图形绘制和IMAGE对象  2. 增加前向声明&#x2F;&#x2F; 前向声明，显示图像void DisplayImage(CRSImage* pRSImg)">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo">
<meta property="og:url" content="http://example.com/2023/06/05/docs/RSImage/Display_EasyX/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Day 5. EasyX显示图像的基本步骤 全部代码在main.cpp中完成  0. 安装EasyX库从EasyX下载EasyX安装程序，安装即可。 1. 增加头文件1include &lt;graphics.h&gt;	&#x2F;&#x2F;使用EasyX图形绘制和IMAGE对象  2. 增加前向声明&#x2F;&#x2F; 前向声明，显示图像void DisplayImage(CRSImage* pRSImg)">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-06-05T15:25:53.681Z">
<meta property="article:modified_time" content="2022-02-22T04:10:24.203Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
  
<meta name="generator" content="Hexo 6.3.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
        
          <a class="nav-icon" href="/atom.xml" title="RSS Feed"><span class="fa fa-rss"></span></a>
        
        <a class="nav-icon nav-search-btn" title="Search"><span class="fa fa-search"></span></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-docs/RSImage/Display_EasyX" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2023/06/05/docs/RSImage/Display_EasyX/" class="article-date">
  <time class="dt-published" datetime="2023-06-05T15:25:53.681Z" itemprop="datePublished">2023-06-05</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="Day-5-EasyX显示图像的基本步骤"><a href="#Day-5-EasyX显示图像的基本步骤" class="headerlink" title="Day 5. EasyX显示图像的基本步骤"></a>Day 5. EasyX显示图像的基本步骤</h1><blockquote>
<p>全部代码在main.cpp中完成</p>
</blockquote>
<h2 id="0-安装EasyX库"><a href="#0-安装EasyX库" class="headerlink" title="0. 安装EasyX库"></a>0. 安装EasyX库</h2><p>从<a target="_blank" rel="noopener" href="http://easyx.cn/">EasyX</a>下载EasyX安装程序，安装即可。</p>
<h2 id="1-增加头文件"><a href="#1-增加头文件" class="headerlink" title="1. 增加头文件"></a>1. 增加头文件</h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include &lt;graphics.h&gt;	<span class="comment">//使用EasyX图形绘制和IMAGE对象</span></span><br></pre></td></tr></table></figure>

<h2 id="2-增加前向声明"><a href="#2-增加前向声明" class="headerlink" title="2. 增加前向声明"></a>2. 增加前向声明</h2><p>&#x2F;&#x2F; 前向声明，显示图像<br>void DisplayImage(CRSImage* pRSImg);</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## 3. 实现 DisplayImage函数</span><br><span class="line">```c++</span><br><span class="line">//////////////////////////////////////////////////////////////////////////</span><br><span class="line">// DisplayImage - 显示图像到控制台窗口									//</span><br><span class="line">// CRSImage* pRSImg - 图像数据指针										//</span><br><span class="line">// 返回值 - void														//</span><br><span class="line">//////////////////////////////////////////////////////////////////////////</span><br><span class="line">void DisplayImage(CRSImage* pRSImg)</span><br><span class="line">&#123;</span><br><span class="line">	// 参数判断</span><br><span class="line">	if (pRSImg==NULL)</span><br><span class="line">		return;</span><br><span class="line">	</span><br><span class="line">        initgraph(m_nSamples, m_nLines);</span><br><span class="line"></span><br><span class="line">	int		i, j;	</span><br><span class="line">	int		nBands = pRSImg-&gt;GetBands();		//波段</span><br><span class="line">	int		nSamples = pRSImg-&gt;GetSamples();	//列</span><br><span class="line">	int		nLines = pRSImg-&gt;GetLines();		//行</span><br><span class="line">	unsigned char***	pppData = pRSImg-&gt;GetDataBuffer();	//三维数组头指针</span><br><span class="line">	unsigned char**		ppRed = pppData[0];		//红色通道的波段</span><br><span class="line">	unsigned char**		ppGrn = nBands&gt;2 ? pppData[1] : pppData[0];	//绿色通道的波段</span><br><span class="line">	unsigned char**		ppBlu = nBands&gt;2 ? pppData[2] : pppData[0];	//蓝色通道的波段</span><br><span class="line"></span><br><span class="line">        // 创建EasyX IMAGE对象</span><br><span class="line">	IMAGE	img(m_nSamples, m_nLines);</span><br><span class="line">	DWORD*	pImgBuffer = GetImageBuffer(&amp;img);</span><br><span class="line"></span><br><span class="line">	// 遍历像素，显示图像</span><br><span class="line">	for (i = 0; i &lt; m_nLines; i++)</span><br><span class="line">	&#123;</span><br><span class="line">		for (j = 0; j &lt; m_nSamples; j++)</span><br><span class="line">		&#123;</span><br><span class="line">			pImgBuffer[i*m_nSamples + j] = RGB(m_pppData[nRedBand][i][j], m_pppData[nGrnBand][i][j],</span><br><span class="line">				m_pppData[nBluBand][i][j]);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// 绘制影像</span><br><span class="line">	putimage(0, 0, &amp;img);</span><br><span class="line"></span><br><span class="line">	// 等待用户按 ESC，退出显示窗口</span><br><span class="line">	while (!_kbhit())</span><br><span class="line">	&#123;</span><br><span class="line">		if (_getch() == 27)</span><br><span class="line">			break;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	// 关闭绘制窗体</span><br><span class="line">	closegraph();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="4-调用Display函数"><a href="#4-调用Display函数" class="headerlink" title="4. 调用Display函数"></a>4. 调用Display函数</h2><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 在图像文件打开之后，就可以调用图像显示</span></span><br><span class="line">...</span><br><span class="line">  <span class="keyword">case</span> <span class="string">&#x27;O&#x27;</span>:</span><br><span class="line">	...</span><br><span class="line">	rsImg.<span class="built_in">Open</span>(...);</span><br><span class="line">	<span class="keyword">if</span> (rsImg.<span class="built_in">IsOpen</span>())</span><br><span class="line">		<span class="built_in">DisplayImage</span>(&amp;rsImg);</span><br><span class="line">	<span class="keyword">break</span>;</span><br></pre></td></tr></table></figure>
<p>你若有兴趣，可以修改DisplayImage的接口，实现图像的定制化显示，如：波段组合等。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2023/06/05/docs/RSImage/Display_EasyX/" data-id="clij09mc40008c8n5h6gme5e0" data-title="" class="article-share-link"><span class="fa fa-share">Share</span></a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2023/06/05/docs/RSImage/Filter/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          (no title)
        
      </div>
    </a>
  
  
    <a href="/2023/06/05/docs/RSImage/Display/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title"></div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2023/06/">June 2023</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2023/06/05/png/RSCmdManual/">(no title)</a>
          </li>
        
          <li>
            <a href="/2023/06/05/docs/RSImage/Subject/">(no title)</a>
          </li>
        
          <li>
            <a href="/2023/06/05/docs/RSImage/Statistics/">(no title)</a>
          </li>
        
          <li>
            <a href="/2023/06/05/docs/RSImage/RSImageFormat/">(no title)</a>
          </li>
        
          <li>
            <a href="/2023/06/05/docs/RSImage/RSCmdManual/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2023 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.6.4.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>